package ale.android.application;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import ale.android.R;
import ale.android.mapping.BcnMap;
import ale.android.remind.ReminderPreferences;
import ale.android.taxiDrivers.TaxiDrivers;
import ale.android.webservice.Prices;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import ale.android.mapping.*;

public class Menu extends ListActivity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ArrayList<String> list = new ArrayList<String>();

		try {

			InputStream in = getResources().openRawResource(R.raw.menu);

			if (in != null) {
				InputStreamReader tmp = new InputStreamReader(in);
				BufferedReader reader = new BufferedReader(tmp);
				String str;
				while ((str = reader.readLine()) != null) {
					list.add(str);
				}
			}
			in.close();

		} catch (java.io.FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		setListAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, list));

	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		String item = (String) getListAdapter().getItem(position);

		if (item.compareTo("Show position") == 0) {
			Intent i = new Intent(this, BcnMap.class);
			startActivity(i);
		} else if(item.compareTo("MyTaxi drivers") == 0){
			Intent i = new Intent(this, TaxiDrivers.class);
			startActivity(i);	
		} else if(item.compareTo("MyTaxi control") == 0){
			Intent i = new Intent(this, taxiControl.class);
			startActivity(i);	
		} else if(item.compareTo("Reminder preferences") == 0){
			Intent i = new Intent(this, ReminderPreferences.class);
			startActivity(i);	
		} else if(item.compareTo("View prices") == 0){
			Intent i = new Intent(this, Prices.class);
			startActivity(i);	
		}
		
	}
}